package cn.biao.epic.sys.modular.system.service.impl;

import cn.biao.epic.core.util.ToolUtil;
import cn.biao.epic.sys.modular.system.entity.UserPos;
import cn.biao.epic.sys.modular.system.mapper.UserPosMapper;
import cn.biao.epic.sys.modular.system.model.params.UserPosParam;
import cn.biao.epic.sys.modular.system.model.result.UserPosResult;
import cn.biao.epic.sys.modular.system.service.UserPosService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * @Auther Uncle_Z
 * @date 2019/12/9 18:40
 * @Email:2545375@qq.com
 * @Descrition
 */
@Service
public class UserPosServiceImpl extends ServiceImpl<UserPosMapper, UserPos> implements UserPosService {

    @Override
    public void add(UserPosParam param){
        UserPos entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(UserPosParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(UserPosParam param){
        UserPos oldEntity = getOldEntity(param);
        UserPos newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public UserPosResult findBySpec(UserPosParam param){
        return null;
    }

    @Override
    public List<UserPosResult> findListBySpec(UserPosParam param){
        return null;
    }


    private Serializable getKey(UserPosParam param){
        return param.getUserPosId();
    }

    private Page getPageContext() {
        return new Page<UserPos>(1,20);
    }

    private UserPos getOldEntity(UserPosParam param) {
        return this.getById(getKey(param));
    }

    private UserPos getEntity(UserPosParam param) {
        UserPos entity = new UserPos();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }
}
